package com.xyht.sca_s.student_manage_system.modules.dormitory.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBuildingAddReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBuildingDeletedReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.entity.req.SmsDormitoryBuildingUpdateReq;
import com.xyht.sca_s.student_manage_system.modules.dormitory.service.SmsDormitoryBuildingService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 宿舍楼栋管理表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-08
 */
@RestController
@RequestMapping("/dormitory/building")
@SecretBody
public class SmsDormitoryBuildingController {

    @Resource
    private JwtTokenUtil jwtTokenUtil;
    @Resource
    private SmsDormitoryBuildingService smsDormitoryBuildingService;

    @ApiOperation("添加楼栋号")
    @PostMapping("/add")
    public ResponseResult addDormitoryBuilding(HttpServletRequest request, @RequestBody SmsDormitoryBuildingAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return smsDormitoryBuildingService.addDormitoryBuilding(userId,addReq);
    }


    @ApiOperation("删除楼栋号")
    @PostMapping("/deleted")
    public ResponseResult deletedDormitoryBuilding(@RequestBody SmsDormitoryBuildingDeletedReq deletedReq){
        return smsDormitoryBuildingService.deletedDormitoryBuilding(deletedReq);
    }


    @ApiOperation("修改楼栋号")
    @PostMapping("/update")
    public ResponseResult updateDormitoryBuilding(@RequestBody SmsDormitoryBuildingUpdateReq updateReq){
        return smsDormitoryBuildingService.updateDormitoryBuilding(updateReq);
    }

    @ApiOperation("查看楼栋列表")
    @GetMapping("/getDormitoryBuildingList")
    public ResponseResult getDormitoryBuildingList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   @RequestParam(value = "name", required = false) String name){
        return smsDormitoryBuildingService.getDormitoryBuildingList(pageNum,pageSize,name);
    }



}

